import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect: '/dashboard',
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login.vue'),
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: () => import('../views/Dashboard.vue'),
    },
    {
      path: '/tasks',
      name: 'tasks',
      component: () => import('../views/TaskListView.vue'),
    },
    {
      path: '/tasks/create',
      name: 'task-create',
      component: () => import('../views/TaskFormView.vue'),
    },
    {
      path: '/tasks/:id/edit',
      name: 'task-edit',
      component: () => import('../views/TaskFormView.vue'),
    },
    {
      path: '/templates',
      name: 'templates',
      component: () => import('../views/TemplateListView.vue'),
    },
    {
      path: '/templates/create',
      name: 'template-create',
      component: () => import('../views/TemplateFormView.vue'),
    },
    {
      path: '/templates/:id/edit',
      name: 'template-edit',
      component: () => import('../views/TemplateFormView.vue'),
    },
    {
      path: '/datacollection',
      name: 'datacollection-overview',
      component: () => import('../views/DataCollectionOverviewView.vue'),
    },
    {
      path: '/storage-statistics',
      name: 'storage-statistics',
      component: () => import('../views/StorageStatisticsView.vue'),
    },
    {
      path: '/data-quality-report',
      name: 'data-quality-report',
      component: () => import('../views/DataQualityReportView.vue'),
    },
    {
      path: '/collection-monitor',
      name: 'collection-monitor',
      component: () => import('../views/CollectionMonitorView.vue'),
    },
    {
      path: '/test',
      name: 'test',
      component: () => import('../views/TestView.vue'),
    },
    // 数据检控相关路由
    {
      path: '/datacontrol',
      name: 'datacontrol-overview',
      component: () => import('../views/DataControlOverviewView.vue'),
    },
    {
      path: '/datacontrol/rules',
      name: 'datacontrol-rules',
      component: () => import('../views/DataControlRuleListView.vue'),
    },
    {
      path: '/datacontrol/rules/create',
      name: 'datacontrol-rule-create',
      component: () => import('../views/DataControlRuleFormView.vue'),
    },
    {
      path: '/datacontrol/rules/:id',
      name: 'datacontrol-rule-detail',
      component: () => import('../views/DataControlRuleFormView.vue'),
    },
    {
      path: '/datacontrol/rules/:id/edit',
      name: 'datacontrol-rule-edit',
      component: () => import('../views/DataControlRuleFormView.vue'),
    },
    {
      path: '/datacontrol/groups',
      name: 'datacontrol-groups',
      component: () => import('../views/DataControlGroupView.vue'),
    },
    {
      path: '/datacontrol/execution',
      name: 'datacontrol-execution',
      component: () => import('../views/DataControlExecutionView.vue'),
    },
    // 主布局路由
    {
      path: '/main',
      component: () => import('../layouts/MobileLayout.vue'),
      redirect: '/main/dashboard',
      children: [
        // 系统概览
        {
          path: 'dashboard',
          name: 'main-dashboard',
          component: () => import('../views/MobileDashboard.vue'),
        },
        // 智能参数引擎模块
        {
          path: 'param-engine',
          name: 'param-engine',
          children: [
            {
              path: 'dashboard',
              name: 'param-engine-dashboard',
              component: () => import('../views/param-engine/MobileDashboard.vue'),
            },
            {
              path: 'categories',
              name: 'param-categories',
              component: () => import('../views/param-engine/Categories.vue'),
            },
            {
              path: 'definitions',
              name: 'param-definitions',
              component: () => import('../views/param-engine/Definitions.vue'),
            },
            {
              path: 'definitions/:id',
              name: 'param-definition-detail',
              component: () => import('../views/param-engine/DefinitionDetail.vue'),
            },
            {
              path: 'values',
              name: 'param-values',
              component: () => import('../views/param-engine/Values.vue'),
            },
            {
              path: 'rules',
              name: 'param-rules',
              component: () => import('../views/param-engine/Rules.vue'),
            },
            {
              path: 'ai-recommendations',
              name: 'param-ai-recommendations',
              component: () => import('../views/param-engine/Recommendations.vue'),
            },
            {
              path: 'monitoring',
              name: 'param-monitoring',
              component: () => import('../views/param-engine/Monitoring.vue'),
            },
          ]
        }
      ]
    },
    // 数据采集模块路由
    {
      path: '/collection',
      name: 'collection',
      redirect: '/collection/data-collection',
      children: [
        {
          path: 'data-collection',
          name: 'data-collection',
          component: () => import('../views/collection/DataCollection.vue'),
          meta: {
            title: '数据采集',
            requiresAuth: true
          }
        },
        {
          path: 'exception-management',
          name: 'exception-management',
          component: () => import('../views/collection/ExceptionManagement.vue'),
          meta: {
            title: '异常数据管理',
            requiresAuth: true
          }
        },
        {
          path: 'data-log',
          name: 'data-log',
          component: () => import('../views/collection/DataLogQuery.vue'),
          meta: {
            title: '数据日志查询',
            requiresAuth: true
          }
        }
      ]
    },
    {
      path: '/customs/multiple',
      name: 'customs-multiple',
      component: () => import('../views/MultipleQueries/Multiple.vue'),
      meta: { title: '海关数据查询' }
    },
    {
      path: '/AnomalyMonitoring/Anomaly',
      name: 'AnomalyMonitoring-Anomaly',
      component: () => import('../views/AnomalyMonitoring/Anomaly.vue'),
      meta: { title: '异动监测' }
    }
  ],
})

export default router
